import $ from 'jquery'

class System {
  static ENV_DEV: string = 'dev'
  static ENV_STAGINE: string = 'staging'
  static ENV_PRD: string = 'prod'
  static env: string = System.ENV_DEV
  static _xhrSupportProgressEvent: any = null
  static log (e: string) {
   if (this.env === this.ENV_DEV) {
     try {
      window.console.log(e)
     } catch (n) {}
   }
  }
  static isTouchDevice () {
    try {
      return document.createEvent('TouchEvent'), !0
    } catch (e) {
      return !1
    }
  }
  static isMobile () {
    let e = ['iphone', 'android', 'ipod', 'ipad'], t = !1;
    for (let n = 0; n < e.length; n++) {
      if (navigator.appVersion.toLowerCase().indexOf(e[n]) > -1) {
        t = !0;
        break
      }
    }
    return t
  }
  static isSupportCSS3Transform () {
    let t = $('<div><div>'),
      n = 'scale(2,2)',
      r = ['-webkit-transform', '-moz-transform', '-o-transform', '-ms-transform', 'transform'];
    let i = !1;
    $.each(r, function (e, n) {
      let r = t.css(n);
      return r !== undefined && r.toLowerCase().indexOf('scale') > -1 ? (i = !0, !1) : !0
    })
    return i
  }
  static isSupportCanvas () {
    let e = !1;
    try {
      let t = document.createElement('canvas');
      t.getContext('2d'), e = !0
    } catch (n) {
      e = !1;
    }
    return e
  }
  static isSupportMotion () {
    let e = window['DeviceOrientationEvent'] !== undefined
    return e
  }
  static inWechatBrowser () {
    let e = /MicroMessenger/i,
        t = navigator.userAgent;
    return e.test(t)
  }
  static xhrSupportProgressEvent () {
    if (this._xhrSupportProgressEvent === null) {
      let e = this.nativeXHR();
      this._xhrSupportProgressEvent = typeof e['onprogress'] !== 'undefined'
    }
    return this._xhrSupportProgressEvent
  }
  static vendorJSProp (e: any, t: string) {
    let n = undefined;
    if (e[t] !== undefined) {
      n = e[t]
    } else {
      let r = t.slice(0, 1).toUpperCase() + t.slice(1, t.length),
          i = ["webkit", "moz", "o", "ms"];
      for (let s = 0; s < i.length; s++) {
          let o = i[s] + r;
          if (e[o] != undefined) {
              n = e[o];
              break
          }
      }
    }
    return n
  }
  static vendorPrefix () {
    let e = null;
    return document["hidden"] != undefined ? e = "" : document["webkitHidden"] != undefined ? e = "webkit" : document["mozHidden"] != undefined ? e = "moz" : document["oHidden"] != undefined ? e = "o" : document["msHidden"] != undefined && (e = "ms"),
        e
  }
  static addVendorPrefix (e: string) {
    let n = null,
        r = this.vendorPrefix();
    return r != null && (r.length <= 0 ? n = e : n = r + e.slice(0, 1).toUpperCase() + e.slice(1, e.length)),
        n
  }
  static nativeXHR () {
    let e = null;
    if (window['XMLHttpRequest'] !== undefined) {
      e = new XMLHttpRequest;
    } else {
      try {
        e = new ActiveXObject('MSXML2.XMLHTTP')
      } catch (t) {
        try {
          e = new ActiveXObject('Microsoft.XMLHTTP')
        } catch (t) {
          e = null
        }
      }
    }
    return e
  }
}

export default System
